﻿using KPI.Data;
using KPI.Entity;
using KPI.Entity.Entitys.Dto;
using KPI.Entity.Entitys.Https;
using System;
using System.Collections.Generic;
using TYBase;

namespace KPI.Api.Apis
{
    public class QuestionBankApi
    {
        public static R<string> CreateQuestionBank(QuestionBankInfoVO dto)
        {
            try
            {
                ///curl -X POST "http://47.106.205.158:8895/luna/assist/v1/login/entry?id=1002" -H "accept: */*" -d ""
                //SecurityUtil.encryptReqData(param, appid, appSecret, true);
                LocalHttp http = new LocalHttp();
                http.SetData(dto).SetBaseUri(KPIData.ServerURL).SetUrl($"/question/bank").SetPost();
                if (!http.Excute(out var data))
                {
                    return R<string>.Fail("数据异常");
                }
                return data.AsModel<R<string>>();


            }
            catch (Exception ex)
            {
                return R<string>.Fail("数据异常");
            }
        }

        public static R<string> DeleteQuestionBank(string id)
        {
            try
            {
                ///curl -X POST "http://47.106.205.158:8895/luna/assist/v1/login/entry?id=1002" -H "accept: */*" -d ""
                //SecurityUtil.encryptReqData(param, appid, appSecret, true);
                LocalHttp http = new LocalHttp();
                http.SetData(new { deleteId = id }).SetBaseUri(KPIData.ServerURL).SetUrl($"/question/bank").SetDelete();
                if (!http.Excute(out var data))
                {
                    return R<string>.Fail("数据异常");
                }
                return data.AsModel<R<string>>();


            }
            catch (Exception ex)
            {
                return R<string>.Fail("数据异常");
            }
        }
        public static R<int> UpdateQuestionBank(QuestionBankInfoVO dto)
        {
            try
            {
                ///curl -X POST "http://47.106.205.158:8895/luna/assist/v1/login/entry?id=1002" -H "accept: */*" -d ""
                //SecurityUtil.encryptReqData(param, appid, appSecret, true);
                LocalHttp http = new LocalHttp();
                http.SetData(dto).SetBaseUri(KPIData.ServerURL).SetUrl($"/question/bank").SetPut();
                if (!http.Excute(out var data))
                {
                    return R<int>.Fail("数据异常");
                }
                return data.AsModel<R<int>>();


            }
            catch (Exception ex)
            {
                return R<int>.Fail("数据异常");
            }
        }
        public static R<bool> EditQuesionBank(QuestionBankInfoVO dto)
        {
            try
            {
                ///curl -X POST "http://47.106.205.158:8895/luna/assist/v1/login/entry?id=1002" -H "accept: */*" -d ""
                //SecurityUtil.encryptReqData(param, appid, appSecret, true);
                LocalHttp http = new LocalHttp();
                http.SetData(dto).SetBaseUri(KPIData.ServerURL).SetUrl($"/question/bank").SetPut();
                if (!http.Excute(out var data))
                {
                    return R<bool>.Fail("数据异常");
                }
                return data.AsModel<R<bool>>();


            }
            catch (Exception ex)
            {
                return R<bool>.Fail("数据异常");
            }
        }

        ///luna/assist/v1/question/item
        public static R<QuestionBankInfoVO> GetQuestionAllInfo(string qbId)
        {
            try
            {
                ///curl -X POST "http://47.106.205.158:8895/luna/assist/v1/login/entry?id=1002" -H "accept: */*" -d ""
                //SecurityUtil.encryptReqData(param, appid, appSecret, true);
                LocalHttp http = new LocalHttp();
                http.SetGetData(new { id = qbId }).SetBaseUri(KPIData.ServerURL).SetUrl($"/question/bank_all");
                if (!http.Excute(out var data))
                {
                    return R<QuestionBankInfoVO>.Fail("数据异常");
                }
                return data.AsModel<R<QuestionBankInfoVO>>();


            }
            catch (Exception ex)
            {
                return R<QuestionBankInfoVO>.Fail("数据异常");
            }
        }


        public static R<RP<QuestionBankInfoVO>> GetQuestionBankList(QuestionBankQueryDto dto)
        {
            try
            {
                ///curl -X POST "http://47.106.205.158:8895/luna/assist/v1/login/entry?id=1002" -H "accept: */*" -d ""
                //SecurityUtil.encryptReqData(param, appid, appSecret, true);
                LocalHttp http = new LocalHttp();
                http.SetGetData(dto).SetBaseUri(KPIData.ServerURL).SetUrl($"/question/bank");
                if (!http.Excute(out var data))
                {
                    return R<RP<QuestionBankInfoVO>>.Fail("数据异常");
                }
                return data.AsModel<R<RP<QuestionBankInfoVO>>>();


            }
            catch (Exception ex)
            {
                return R<RP<QuestionBankInfoVO>>.Fail("数据异常");
            }
        }
    }
}
